package com.yt.ds.util;

/**
 * @Author: lzf
 * @Date: 2020/7/10 18:01
 * @Description: 排序工具
 */
public class SortUtil {
    // 交换
    public static void exch(Comparable[] a, int i, int j) {
        Comparable obj = a[i];
        a[i] = a[j];
        a[j] = obj;
        display(a, i, j);
    }

    // 展示
    public static void display(Comparable[] a) {
        for (Comparable comparable : a) {
            System.out.print(comparable + " ");
        }
        System.out.println();
    }

    // 展示 交换的输出红色字体
    public static void display(Comparable[] a, int i, int j) {
        for (int k = 0; k < a.length; k++) {
            Comparable comparable = a[k];
            String str = comparable + " ";
            if (k == i || k == j) {
                str = FontUtil.redPrint(str);
            }
            System.out.print(str);
        }
        System.out.println();
    }

    /**
     * a[i] 比 a[j] 小
     */
    public static boolean less(Comparable[] a, int i, int j) {
        return a[i].compareTo(a[j]) < 0;
    }
}
